#
# This file is a part of the open-eBackup project.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at
# http://mozilla.org/MPL/2.0/.
#
# Copyright (c) [2024] Huawei Technologies Co.,Ltd.
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
#

import uuid
import os
import subprocess
import time
import json

from common.common import execute_cmd
from common.logger import Logger
from db2.comm.constant import DB2Type
from db2.comm.error_code import Db2ErrCode
from db2.comm.param_parse import Param
from db2.comm.util.common_util import Db2CommonUtil
from common.const import ParamConstant, CMDResult

LOGGER = Logger().get_logger(filename="db2.log")


class DataBaseSizeInfo:
    # 数据库信息查询
    def __init__(self, pid, param: Param):
        self.pid = pid
        self.context = param
        self.instance = self.context.application
        self.user_name = self.context.app_auth_key
        self.database_name = self.instance.get("name")

    def datasize_for_databases(self):
        LOGGER.info(f"Begin to get db2 data size from  pid :{self.pid}")
        result_list = []
        resource = dict()
        resource["name"] = self.database_name
        data_size = Db2CommonUtil.get_database_size(self.user_name, self.database_name)
        extend_info = {"dataSize": str(data_size)}
        LOGGER.info(f"datasize :{str(data_size)}")
        resource["extendInfo"] = extend_info
        result_list.append(resource)
        params = {"resourceList": result_list}
        return params
